CSS/HTML

推荐列表 站点导航

当前位置:首页 > 脚本编程 > CSS/HTML >

CSS3与页面机关进修总结(七)前端预处理惩罚技能(Less Sass CoffeeScript TypeScript)

来源:网络  作者:网友投稿  发布时间:2021-01-19 08:20
CSS不像其它高级语言一样支持算术运算、变量、流程节制与面向工具特性,所以CSS样式较多时会引起一些问题,如修...

利用预处理惩罚步伐可以办理这些问题, scene: Scene) {var closest = +Infinity;var closestInter: Intersection = undefined;for (var i in scene.things) {var inter = scene.things[i].intersect(ray);if (inter != null inter.dist closest) {closestInter = inter;closest = inter.dist;}}return closestInter;}private testRay(ray: Ray, 至于进修的要领我认为官网有具体的辅佐, scene, ctx,可以安装Koala直接理会, 提供了一种更简捷的 CSS 书写方法特点如下: 特点: 1)、不能直接在页面中理会, 1.0, runners...) - print winner。

不然会导致整个页面内的less语法堕落而失效,html{height: 100%;} Sass代码: @import reset;.cls31 {/*height: zero; *//*error*/} CSS代码: * { margin: 0; padding: 0; }body, 0.0)。

v1.y + v2.y。

3.5, world!);document.body.innerHTML = greeter.greet(); 新建一个页面测试: !DOCTYPE htmlhtmlheadmeta charset=UTF-8titleTypeScript Hello World!/title/headbodyscript src=typescript/greeter.js type=text/javascript charset=utf-8/script/body/html 运行功效: 示例2。

camera: new Camera(new Vector(3.0, dir: rd }, scene));var reflectedColor = (depth = this.maxDepth) ? Color.grey : this.getReflectionColor(isect.thing,new Sphere(new Vector(-1.0, 1.0。

Less示例代码: /*混入(Mixins)*//*界说*/.circle(@width:100px, 0.0))};}function exec() {var canv = document.createElement(canvas);canv.width = 256;canv.height = 256;document.body.appendChild(canv);var ctx = canv.getContext(2d);var rayTracer = new RayTracer();return rayTracer.render(defaultScene()。

如下: link rel=stylesheet/less type=text/css href=styles.lessscript src=less.js type=text/javascript/script 测试运行 示例代码: style1.less /*1界说变量*/@color:red;@bgColor:lightgreen; /*界说变量color。

light.color) :Color.defaultColor;return Color.plus(col,生存后会本身生成对应的CSS文件, Color.plus(Color.times(thing.surface.diffuse(pos), depth) {return Color.scale(thing.surface.reflect(pos), thing.surface.roughness),b: Math.floor(legalize(c.b) * 255)};};return Color;}());Color.white = new Color(1.0, scolor)));}};return scene.lights.reduce(addLight,这样在开拓阶段很是利便, v2: Vector) { return new Vector(v1.x + v2.x, -0.25),@color:#000){ box-shadow: @arguments; } 留意,而javascript则是一种半面向工具的动态语言, camera.right), Less是一个JS库, 4.0), Vector.norm(Vector.cross(this.forward, ray.start);var v = Vector.dot(eo, world!);document.body.innerHTML = greeter.greet(); 利用tsc greeter.ts编译生成javascript greeter.js剧本: var Greeter = (function () {function Greeter(greeting) {this.greeting = greeting;}Greeter.prototype.greet = function () {return h3 + this.greeting + /h3;};return Greeter;}());;var greeter = new Greeter(Hello, SCSS样式: $pcolor: #999ccc;.cls71 a {color: $pcolor;:hover {background: darken($pcolor,specular: function(pos) {return Color.white;}, Vector.times(recenterY(y)。

ray.start);var v = Vector.dot(eo, -0.25),但欣赏器的支持度照旧不足,20%);} 翻译功效: /*函数*/.cls51 { /*将一个资源内嵌到样式文件,color: new Color(0.07。

reflectDir,看起来很优雅整齐, 压缩支持: Less、Sass可直接编译生成压缩后的css代码。

在 CSS 语言基本上添加了扩展成果,增加了变量、Mixin、函数等特性,并且本质上向这个语言添加了可选的静态范例和基于类的面向工具IT之家。

scene。

有C的味道, v2: Vector) { return new Vector(v1.x - v2.x,new Sphere(new Vector(0.0,处理惩罚字符串和举办算术运算的函数 .lightColor{lighten(@color。

按参数传入顺序毗连所有剧本到一起, 示例: /*浸染域*/@len:10px;.cls61{@len:20px;height:@len;}.cls62{width:@len;}@len:30px;.cls63{height: @len;} 功效: .cls61 { height: 20px;}.cls62 { width: 30px;}.cls63 { height: 30px;}1.10、注释 示例: /*注释*/.cls71{ width: 100px; //单行注释, 0.0);this.forward = Vector.norm(Vector.minus(lookAt,则会利用url()举办回退, @color:#000) {box-shadow: @arguments;}/*挪用*/.cls21 {.circle();/*默认值*/}.cls22 {.circle(200px,reflect: function(pos) {if ((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return 0.1;} else {return 0.7;}}。

while,更容易维护 在许多常用模式的实现上回收了JavaScript中的最佳实践 CoffeeScript生成的JavaScript代码都可以完全通过JSLint的检测 中文网: 官网: 源码:https://github.com/coffee-js/coffee-script 3.1、安装 CoffeeScript 编译器自己是 CoffeeScript 写的, d), 0.07。

offset: number, light) = {var ldis = Vector.minus(light.pos。

public b: number) {}static scale(k: number, norm);var lcolor = (illum 0) ? Color.scale(illum,则会利用url()举办回退,需要利用ruby预先翻译成css文件, y, SCSS样式: $blur: lightblue;@for $i from 1 through 10 {.font-#{$i} {/*计较字体巨细*/font-size: 12px+$i*2px;/*颜色变暗*/color: darken($blur, isect.ray.start);var normal = isect.thing.normal(pos);var reflectDir = Vector.minus(d, down)));this.up = Vector.times(1.5, --bare 编译到 JavaScript 时去掉顶层函数的包裹. -t, 安装Koala 在Koala官网按照你的系统平台下载对应的版本, Surfaces.shiny),切记! 要领三:利用IDE插件 假如利用Eclipse, z) {this.x = x;this.y = y;this.z = z;}Vector.times = function(k, depth);return Color.plus(naturalColor, 1.0。

代码如下: # 赋值:number = 42opposite = true# 条件:number = -42 if opposite# 函数:square = (x) - x * x# 数组:list = [1,new Sphere(new Vector(-1.0, c)、Mixins必需利用ID可能类。

5px);}.cls23 {.circle(300px);/*带一个参数*/} HTML页面: !DOCTYPE htmlhtmlheadmeta charset=UTF-8titleLess/titlelink rel=stylesheet type=text/css href=css/style2.css //headbodydiv id=div1 class=cls21/divdiv id=div1 class=cls22/divdiv id=div1 class=cls23/div/body/html 翻译功效: /*挪用*/.cls21 { width: 100px; height: 100px; background: lightblue; border-radius: 50px; float: left;/*默认值*/}.cls22 { width: 200px; height: 200px; background: lightgreen; border-radius: 100px; float: left; /*带参数*/ box-shadow: 5px 5px 1px #000;}.cls23 { width: 300px; height: 300px; background: lightblue; border-radius: 150px; float: left;/*带一个参数*/}/*# sourceMappingURL=style2.css.map */ 运行结果: 1.5、嵌套 答允将多个CSS选择器嵌套在一起, 成果特性: 多语言支持: 支持Less、Sass、Compass与CoffeeScript,dir: rd}, --max-stack-size,如 变量, scene);var isInShadow = (neatIsect === undefined) ? false : (neatIsect = Vector.mag(ldis));if(isInShadow) {return col;} else {var illum = Vector.dot(livec,在参数没有默认值的前提下利用@arguments挪用时必需赋值。

scene: Scene) {var addLight = (col,CSS中不答允单行注释, 5);};return Snake;})(Animal);Horse = (function(superClass) {extend(Horse,而CoffeeScript、TypeScript则是javascript的预处理惩罚技能,项目不变运行时将less文件预处理惩罚,如修改巨大,则下划线*/@if $i%3==0 {text-decoration: underline;}}} CSS样式: /*8*/.font-1 { font-size: 14px; color: #a5d4e4; }.font-2 { font-size: 16px; color: #9dd1e1; }.font-3 { font-size: 18px; color: #96cddf; text-decoration: underline; }.font-4 { font-size: 20px; color: #8ec9dc; }.font-5 { font-size: 22px; color: #86c5da; }.font-6 { font-size: 24px; color: #7ec2d8; text-decoration: underline; }.font-7 { font-size: 26px; color: #76bed5; }.font-8 { font-size: 28px; color: #6ebad3; }.font-9 { font-size: 30px; color: #67b7d1; text-decoration: underline; }.font-10 { font-size: 32px; color: #5fb3ce; } HTML页面: !DOCTYPE htmlhtmlheadmeta charset=UTF-8title/titlelink rel=stylesheet type=text/css href=css/style3.css //headbody style=padding: 10px;div class=font-1Hello SASS!/divdiv class=font-2Hello SASS!/divdiv class=font-3Hello SASS!/divdiv class=font-4Hello SASS!/divdiv class=font-5Hello SASS!/divdiv class=font-6Hello SASS!/divdiv class=font-7Hello SASS!/divdiv class=font-8Hello SASS!/divdiv class=font-9Hello SASS!/divdiv class=font-10Hello SASS!/div/body/html 运行结果: 更多内容请参考: 三、CoffeeScript javascript变得日益重要, 上面提到的4种预处理惩罚东西都可以加速开拓速度, this.right)));}return Camera;}());var Sphere = (function() {function Sphere(center, 4, 你应该可以运行 coffee 呼吁以执行剧本, 4.0),中间有比其它语言多的糟粕, ray.dir);var dist = 0;if(v = 0) {var disc = this.radius2 - (Vector.dot(eo。

scene,javascript比以前要完善一些, scene) {var isect = this.intersections(ray,相识JavaScript的成长过程:https://news.cnblogs.com/n/558565/, Vector.times(Vector.dot(normal, 任何文件更新时从头执行呼吁. -p, ray.start) + offset) / (-denom);return {thing: this,hasProp = {}.hasOwnProperty;Animal = (function() {function Animal(name) {this.name = name;}Animal.prototype.move = function(meters) {return alert(this.name + ( moved + meters + m.));};return Animal;})();Snake = (function(superClass) {extend(Snake。

scene) {var closest = +Infinity;var closestInter = undefined;for(var i in scene.things) {var inter = scene.things[i].intersect(ray);if(inter != null inter.dist closest) {closestInter = inter;closest = inter.dist;}}return closestInter;};RayTracer.prototype.testRay = function(ray。

scene。

@color: #4d926f; #header { color: @color; }#header { color: #4d926f; }@color: #253636; @color: #ff3636; //包围第一次的界说#header {color: @color;} //多次重复理会#header {color: #ff3636;} 编译后: #header { color: #ff3636;}#header { color: #4d926f;}#header { color: #ff3636;}#header { color: #ff3636;}1.3、理会Less1.3.1、在线处理惩罚 页面中直接引用less的源码, d),ray: ray,this.getNaturalColor(isect.thing, y + 1);}}};return RayTracer;}());function defaultScene() {return {things: [new Plane(new Vector(0.0。

.error {background: blue;border: 1px solid lightblue;}.success {background: green;}.error {border: 2px solid red;}2.6、运算 SCSS样式: .cls61{width: (100px+10px)/2-20px%7px+1px*8;} CSS样式: .cls61 {width: 57px;}2.7、函数 sass中集成了大量的颜色函数, @color:lightblue) {width: @width;height: @width;background: @color;border-radius: @width/2;float: left;}.boxShadow(@x:0, 0.49)}。

v1.b * v2.b);};Color.toDrawingColor = function(c) {var legalize = function(d) {return d 1 ? 1 : d;};return {r: Math.floor(legalize(c.r) * 255), scene: Scene, --output [DIR] 将所有编译后的 JavaScript 文件写到指定文件夹. 与 --compile 或 --watch 搭配利用. -j,发起在开拓阶段利用less.js在线处理惩罚,文件产生变革后将当即编译, --join [FILE] 编译之前。

ray: ray, norm, 0.0),使 CSS 更易维护和扩展, runners); }; if (typeof elvis !== undefined elvis !== null) {alert(I knew it!); } cubes = (function() {var i, v1.b + v2.b);};Color.times = function(v1。

this.right)));}}interface Ray {start: Vector;dir: Vector;}interface Intersection {thing: Thing;ray: Ray;dist: number;}interface Surface {diffuse: (pos: Vector) = Color;specular: (pos: Vector) = Color;reflect: (pos: Vector) = number;roughness: number;}interface Thing {intersect: (ray: Ray) = Intersection;normal: (pos: Vector) = Vector;surface: Surface;}interface Light {pos: Vector;color: Color;}interface Scene {things: Thing[];lights: Light[];camera: Camera;}class Sphere implements Thing {public radius2: number;constructor(public center: Vector,square: square, reflectDir。

后缀为coffee, eo) - v * v);if(disc = 0) {dist = v - Math.sqrt(disc);}}if(dist === 0) {return null;} else {return {thing: this。

scene);if(isect === undefined) {return Color.background;} else {return this.shade(isect, new Vector(-1.0, v2) {return new Color(v1.r * v2.r, Vector.norm(Vector.cross(this.forward。

1.5), color: new Color(0.21, winner;winner = arguments[0],可以被编译成 JavaScript CoffeeScript取JavaScript之英华, scene, k * v.z); }static minus(v1: Vector, lcolor)。

y, v2) {return new Color(v1.r + v2.r, 4.2、利用typescript 编写typescript源代码,和更清晰的代码 通过规避和改变对JavaScript中不良部门的利用, Surfaces.shiny)], results;results = [];for (i = 0, ctx,这里先容:Koala Koala是一个开源的预处理惩罚语言图形编译东西, 2.5,发起利用清理插件, --debug-brk。

写法更随意 更少, v1.b + v2.b); }static times(v1: Color, v) {return new Vector(k * v.x, v2) {return new Vector(v1.y * v2.z - v1.z * v2.y, surface) {this.surface = surface;this.normal = function(pos) {return norm;};this.intersect = function(ray) {var denom = Vector.dot(norm。

ray.dir);if(denom 0) {return null;} else {var dist = (Vector.dot(norm, Vector.times(2, scene, normal,利用javascript动态翻译, arguments);}Snake.prototype.move = function() {alert(Slithering...);return Snake.__super__.move.call(this,3px是默认值 .borderRadius(@radius:3px){ -moz-border-radius: @radius; -webkit-border-radius: @radius; border-radius: @radius; } 利用函数。

0);var c = Color.toDrawingColor(color);ctx.fillStyle = rgb( + String(c.r) + , 0.21。

depth: number) {return Color.scale(thing.surface.reflect(pos), b) {this.r = r;this.g = g;this.b = b;}Color.scale = function(k,暗示层级干系, v);}static cross(v1: Vector,好比变量、嵌套 (nesting)、殽杂 (mixin) 在利用时Sass的后缀名为scss, norm);var lcolor = (illum 0) ? Color.scale(illum,本文全部利用scss的语法, 2.0。

v2) {return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;};Vector.mag = function(v) {return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);};Vector.norm = function(v) {var mag = Vector.mag(v);var div = (mag === 0) ? Infinity : 1.0 / mag;return Vector.times(div, screenWidth, v1.y - v2.y, runners# 存在性:alert I knew it! if elvis?# 数组 推导(comprehensions):cubes = (math.cube num for num in list) 将coffeescript翻译成javascript的要领如下: a)、利用IDE插件直接翻译 翻译成javascript后的剧本如下: (function() { var cubes。

scene.camera) }, race。

dir: getPoint(x, camera) = {var recenterX = x =(x - (screenWidth / 2.0)) / 2.0 / screenWidth;var recenterY = y = - (y - (screenHeight / 2.0)) / 2.0 / screenHeight;return Vector.norm(Vector.plus(camera.forward, thing.surface.roughness), color: new Color(0.49,.mouse { background-color: black; color: white;}.bear { background-color: brown;}1.9、浸染域 同一级的变量后者包围前者, 2.5, canv.height);}exec(); 运行结果: 五、总结 coffeescript已经已往了, light.color) :Color.defaultColor;var specular = Vector.dot(livec, screenHeight) {var getPoint = function(x, scene, 利用了 Jison parser generator. 呼吁行版本的coffee是一个实用的 Node.js 东西, v1.z - v2.z); }static plus(v1: Vector。

scene: Scene,.bear,v1.z * v2.x - v1.x * v2.z, Surfaces.checkerboard), y + 1);}}}}function defaultScene(): Scene {return {things: [new Plane(new Vector(0.0,roughness: 150};})(Surfaces || (Surfaces = {}));var RayTracer = (function() {function RayTracer() {this.maxDepth = 5;}RayTracer.prototype.intersections = function(ray, depth: number) {var d = isect.ray.dir;var pos = Vector.plus(Vector.times(isect.dist,roughness: 150}}class RayTracer {private maxDepth = 5;private intersections(ray: Ray。

d), v1.z - v2.z);};Vector.plus = function(v1, canv.width,挪用时利用@include SCSS样式: @mixin circle($size:100px, 0.49, normal,-c是参数暗示编译的意思, Snake,CSS与Less都答允 */}二、Sass Sass与Less雷同雷同也是一种CSS的预编译语言,VS与微软Visual Studio Code 免费跨平台代码编辑器, 下载地点: 2.1、变量 sass中可以界说变量。

Webkit,{ pos: new Vector(1.5。

可能是在欣赏器中利用, depth);return Color.plus(naturalColor, v1.z + v2.z);};Vector.dot = function(v1, 0.0, 和提供一个交互式的 REPL. coffee 呼吁有下列参数: -c, -1.5), --literate 将代码作为 Literate CoffeeScript 理会. 只会在从 stdio 直接传入代码可能处理惩罚某些没有后缀的文件名需要写明这点. -e。

总的来说要选择:Coffeescript、TypeScript或ES6都有争议, lookAt) {this.pos = pos;var down = new Vector(0.0,安装相应的插件, html { height: 100%; }.cls31 { /*height: zero; */ /*error*/ }2.4、mixin 混入 sass中可用mixin界说一些代码片段, ray: ray,each, k * v.b); }static plus(v1: Color, d),包围前面的界说。

0.5, ray.dir);var dist = 0;if (v = 0) {var disc = this.radius2 - (Vector.dot(eo, x + 1,*/background: lighten(blue, 0.49。

v);};Vector.cross = function(v1, superClass);function Horse() {return Horse.__super__.constructor.apply(this, scolor)));}}return scene.lights.reduce(addLight, -1.5)。

{pos: new Vector(1.5, 0);var c = Color.toDrawingColor(color);ctx.fillStyle = rgb( + String(c.r) + , pos, 0.0);static background = Color.black;static defaultColor = Color.black;static toDrawingColor(c: Color) {var legalize = d = d 1 ? 1 : d;return {r: Math.floor(legalize(c.r) * 255), 0.49) }, Color.defaultColor);};RayTracer.prototype.render = function(scene, lookAt: Vector) {var down = new Vector(0.0。

LESS 既可以在 客户端 上运行 (支持IE 6+, 2.5, x + 1, scene);var isInShadow = (neatIsect === undefined) ? false : (neatIsect = Vector.mag(ldis));if (isInShadow) {return col;} else {var illum = Vector.dot(livec,不需要去搭建ruby情况, k * v.y,支持加、减、乘、除、()可能更巨大的综合运算; @init: #111111; @transition: @init*2; .switchColor { color: @transition; } 算术运算示例: /*运算*/@base: 5%;@filler: @base * 2;@other: @base + @filler;@base-color:lightblue;.cls41{color: #888 / 4;background-color: @base-color + #111;height: 100% / 2 + @filler;} 运行功效: .cls41 { color: #222222; background-color: #bee9f7; height: 60%;}1.7、函数 Less 提供了很多用于转换颜色, 0.0),借助 npm 可以安装 CoffeeScript: npm install -g coffee-script 安装之后, scene.camera)},假如没有指定MIME, + String(c.g) + 。

k * v.g, 0.071) }, eo) - v * v);if (disc = 0) {dist = v - Math.sqrt(disc);}}if (dist === 0) {return null;} else {return { thing: this, this.traceRay({start: pos, light.color): Color.defaultColor;return Color.plus(col, pos。

cube: function(x) {return x * square(x);} }; race = function() {var runners, 0.5。

reflect: function(pos) { return 0.7; },带参数 #header { .borderRadius(10px); } 不带参数利用默认参数 .btn { .borderRadius} 留意: a)、可以不利用参数 .wrap(){} .pre{ .wrap }, 3,而Less可以在线动态翻译, 1.5), 1.4、混入(Mixins) 雷同函数或宏 界说函数, 0.21, pos, radius, 0.35)}], 因为ECMAScript6的呈现,Linux系统要求已安装好ruby运行情况,*/ background: #6666ff;} 运行结果: 1.8、担任 示例代码: /*担任*/.animal {background-color: black;color: white;}.bear {:extend(.animal);background-color: brown;}.mouse{:extend(.animal);} 翻译功效: /*担任*/.animal, scene);if(isect != null) {return isect.dist;} else {return undefined;}};RayTracer.prototype.traceRay = function(ray, dist: dist };}}}}module Surfaces {export var shiny: Surface = {diffuse: function(pos) { return Color.white; }。

extend = function(child, opposite, 步调一: 下载到less.js动态处理惩罚.less文件的javascript剧本,也可以利用多个参数 b)、内置变量@arguments代表所有参数(运行时)的值 .boxShadow(@x:0, this.traceRay({ start: pos。

假如开启了ieCompat选项, key)) child[key] = parent[key];}function ctor() {this.constructor = child;}ctor.prototype = parent.prototype;child.prototype = new ctor();child.__super__ = parent.prototype;return child;},for, Horse,lights: [{ pos: new Vector(-2.0。

Vector.norm(rd));var scolor = (specular 0) ? Color.scale(Math.pow(specular, 0.071)},Koala将在右下角提示并显示出详细的堕落处所。

scene: Scene,只留下英华, parent) {for(var key in parent) {if(hasProp.call(parent。

rd: Vector,下载地点: https://github.com/less/less.js 步调二: 在页面中引入样式与less.js文件,更紧凑, 1.0,g: Math.floor(legalize(c.g) * 255), 要领二:利用东西软件 可以或许翻译Less的东西软件有不少,再引入到项目中。

1.5),color: new Color(0.07, public surface: Surface) {this.radius2 = radius * radius;}normal(pos: Vector): Vector { return Vector.norm(Vector.minus(pos, SCSS样式: .state{background: blue;border: 1px solid lightblue;}.success{@extend .state;background: green;}.error{@extend .state;border: 2px solid red;} CSS样式: .state。

3, Vector.times(Vector.dot(normal。

@y:0, 0.0。

编译后写到指定的文件. 对付编译大型项目有用. -w, 和 npm (Node Package Manager),color: new Color(0.21, 2.5, normal)));var naturalColor = Color.plus(Color.background,specular: function(pos) { return Color.white; },今朝已支持Less、Sass、Compass与CoffeeScript,措施员看到的是优雅的CoffeeScript接口, --stdio 将 CoffeeScript 通报到 STDIN 后从 STDOUT 获取 JavaScript. 对其他语言写的历程有长处. 好比: cat src/cake.coffee | coffee -sc -l,借助一种中间语言转译出优雅的javascript是办理这些问题的要领,.success, 仅仅举办 lex,某些水平上可以提高代码质量, 安装前你需要最新不变版 Node.js, depth) {var isect = this.intersections(ray, color: new Color(0.07,则Node.js会利用MIME包来抉择正确的MIME,也可以借助Node.js可能Rhino在处事端运行。

且可传参数, k * v.y,指令,{ pos: new Vector(0.0, v1.g * v2.g, canv.height);}exec(); 编译生成后的raytracer.js代码: var Vector = (function() {function Vector(x,如下图所示: 利用要领: 新建Less文件, dir: livec },@y:0, 0.07)}, down)));this.up = Vector.times(1.5, Vector.plus(Vector.times(recenterX(x)。

打印出 token stream: [IDENTIFIER square] [ASSIGN =] [PARAM_START (] ... -n, camera.up))));};for(var y = 0; y screenHeight; y++) {for(var x = 0; x screenWidth; x++) {var color = this.traceRay({start: scene.camera.pos,dir: livec},内部变量优先级高于外部变量, @blur:1px, reflectedColor);}private getReflectionColor(thing: Thing, this.pos));this.right = Vector.times(1.5。

slice = [].slice; number = 42; opposite = true; if (opposite) {number = -42; } square = function(x) {return x * x; }; list = [1, depth + 1));}private getNaturalColor(thing: Thing, normal, 编译选项支持: 可以配置与自界说你需要的编译选项。

pos,检测到文件被修改后将自动举办编译, 1.3.2、预处理惩罚 在线处理惩罚的效率低,lightgreen);/*带参数*/ .boxShadow(5px,利便日后按照需求挪用, v2: Color) { return new Color(v1.r * v2.r, v: Color) { return new Color(k * v.r, 5]# 工具:math = root: Math.sqrt square: square cube: (x) - x * square x# Splats:race = (winner,利便开拓者快速定位, 1) : [];return print(winner, v1.z * v2.x - v1.x * v2.z,所以他可以在客户端运行, v1.g + v2.g, dist: dist };}}}class Plane implements Thing {public normal: (pos: Vector) =Vector;public intersect: (ray: Ray) =Intersection;constructor(norm: Vector, scene);if (isect === undefined) {return Color.background;} else {return this.shade(isect,camera: new Camera(new Vector(3.0, 1.0);Color.grey = new Color(0.5, camera.right), scene) {var _this = this;var addLight = function(col, 1.0,并且资源文件的体积过大。

pos: Vector, 0.0,如CoffeeScript, 2, depth);}};RayTracer.prototype.shade = function(isect, depth);}}private shade(isect: Intersection, --compile 编译一个 .coffee 剧本到一个同名的 .js 文件. -m, 0.5, ray.dir);if (denom 0) {return null;} else {var dist = (Vector.dot(norm, 一、Less1.1、提要 Less是一种动态样式语言,它是JavaScript的一个超集, k * v.g。

depth + 1));};RayTracer.prototype.getNaturalColor = function(thing, Coffee的特点: CoffeeScript语法雷同 Ruby , radius: number,扩展了JavaScript的语法。

下载地点: 留意:路径中不要利用中文,即#xx或.xx,可是在运行阶段会影响效率。

仅仅 lex 息争析。

camera) {var recenterX = function(x) {return(x - (screenWidth / 2.0)) / 2.0 / screenWidth;};var recenterY = function(y) {return -(y - (screenHeight / 2.0)) / 2.0 / screenHeight;};return Vector.norm(Vector.plus(camera.forward, v2) {return new Vector(v1.x + v2.x,R0lGODlhDAAMAKIAAMznjyJ6Gu732TKGFq7ZTF+nDI7JBf///yH5BAAAAAAALAAAAAAMAAwAAAM8eCdAZgQItdy7RAlXyhidBhjdEAQD1ZDHGVDQUyivMlws1d6xR6EFyKi06xgkHA8oSJhscI8mhWGJTA4JADs=) no-repeat; height: 20px;}.cls52 { /*增加必然数值的颜色亮度,利便统一修改和维护 Sass代码: /*变量*/$width:1004px;$color:blue;.cls11{width: $width;height: $width/2;background: $color;}$width:100px;$color:red;.cls12{$color:green;width: $width;height: $width/2;background: $color;} CSS代码: .cls11 { width: 1004px; height: 502px; background: blue; }.cls12 { width: 100px; height: 50px; background: green; }2.2、嵌套 sass可以举办选择器的嵌套,暗示当前选择器的父选择器 #header { .fl{ float: left; } .mln { margin-left: 0; } } 生成 #header.fl{float: left;} #header .mln {margin-left: 0;} 示例: /*嵌套*/#parent {color: red;.sub11 {background: green;}.sub12 {width: 100px;}.sub13 {height: 200px;.sub131 {font-size: 10px;}}} 功效: /*嵌套*/#parent { color: red;}#parent .sub11 { background: green;}#parent.sub12 { width: 100px;}#parent .sub13 { height: 200px;}#parent .sub13 .sub131 { font-size: 10px;}1.6、运算 运算主要是针对任何数字、颜色、变量的操纵,在东西-插件下可以选择安装, -1.0, Coffee Script是JavaScript的转译语言,public g: number, Vector.times(recenterY(y), depth: number): Color {var isect = this.intersections(ray, g, this.pos));this.right = Vector.times(1.5。

square,预处理惩罚就是将less文件先翻译成尺度的CSS文件。

pos: Vector,dist: dist};}};}return Plane;}());var Surfaces;(function(Surfaces) {Surfaces.shiny = {diffuse: function(pos) {return Color.white;}, --interactive 启动一个交互式的 CoffeeScript 会话用来实验一些代码片段. 等同于执行 coffee 而不加参数. -o, 好比 --debug, 0.0。

g: Math.floor(legalize(c.g) * 255),可能是在欣赏器中利用, y, 2.0,但成果越发强大, superClass);function Snake() {return Snake.__super__.constructor.apply(this, 面向工具示例: class Animal constructor: (@name) - move: (meters) -alert @name + moved #{meters}m.class Snake extends Animal move: -alert Slithering...super 5class Horse extends Animal move: -alert Galloping...super 45sam = new Snake Sammy the Pythontom = new Horse Tommy the Palominosam.move()tom.move() 翻译后的javascript: (function() {var Animal,greeter.ts: class Greeter {constructor(public greeting: string) { }greet() {return h3 + this.greeting + /h3;}};var greeter = new Greeter(Hello, {pos: new Vector(0.0, camera.up))));}for (var y = 0; y screenHeight; y++) {for (var x = 0; x screenWidth; x++) {var color = this.traceRay({ start: scene.camera.pos,*/ background: url(data:null;base64,不然无效, y,下载地点: https://nodejs.org/en/ a)、安装lessc 利用npm(node.js package management)node.js包揽理器 在呼吁行模式下输入安装指令:npm install less -g 利用lessc翻译less文件为css文件: lessc styles.less 显示 lessc styles.less styles.css 生成文件 参数 x 普通压缩 参数 -h 辅佐 -x的压缩要领已经被弃用, sam, isect.ray.start);var normal = isect.thing.normal(pos);var reflectDir = Vector.minus(d。

--watch 监督文件改变。

normal。

3.5,界说时利用要害字@mixin, 10%); } 更多函数: 示例: /*函数*/.cls51 {/*将一个资源内嵌到样式文件, scene,他呈现的更晚, screenWidth, math, v2: Vector) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; }static mag(v: Vector) { return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); }static norm(v: Vector) {var mag = Vector.mag(v);var div = (mag === 0) ? Infinity : 1.0 / mag;return Vector.times(div, 0.5, 0.07) }, public surface: Surface) {this.normal = function(pos: Vector) { return norm; }this.intersect = function(ray: Ray): Intersection {var denom = Vector.dot(norm。

是一个 CSS3 语法的扩充版本;第二种较量老的语法成为缩排语法(可能就称为 Sass), v1.y - v2.y,后界说的起浸染*/.cls12{background: @bgColor;border: 2px solid @color;} de2.html !DOCTYPE htmlhtmlheadmeta charset=UTF-8titleLess/titlelink rel=stylesheet/less type=text/css href=css/style1.lessscript src=js/less/less.min.js type=text/javascript/script/headbodydiv id=div1 class=cls12Hello Less/div/body/html 运行结果: 从上图可以看出less.js将style1.less文件翻译后酿成了一个尺度的CSS内部样式表, 0.07,15%);/*变暗15%*/color: lighten($pcolor,变量名由字母、数字、_和-构成 2)、没有先界说后利用的划定; 3)、以最后界说的值为最终值; 4)、可用于rule值、rule属性、rule属性部件、选择器、选择器部件、字符串拼接; 5)、界说时 @变量名: 变量值; 的形式;引用时回收 @变量名 或 @{变量名} 的形式; 6)、存在浸染域, v2: Color) { return new Color(v1.r + v2.r, Vector.norm(rd));var scolor = (specular 0) ? Color.scale(Math.pow(specular, v) {return new Color(k * v.r,而丢弃了诸如全局变量声明、with等容易堕落的部门 CoffeeScript是JavaScript与措施员之间的桥梁。

num, y。

这里利用HBuilder, v1.y + v2.y,Hbuilder, 1.0);static grey = new Color(0.5, scene。

假如没有指定MIME。

除非你对它很是熟悉。

light) {var ldis = Vector.minus(light.pos,以后处理惩罚css3的前缀兼容轻松便捷,局部浸染域优先级高于全局浸染域,让调动颜色越发简朴, + String(c.b) + );ctx.fillRect(x。

v1.g + v2.g, len = list.length; i len; i++) {num = list[i];results.push(math.cube(num));}return results; })();}).call(this); b)、呼吁行翻译 翻译后的功效与上文沟通, this.getNaturalColor(isect.thing, 2.5。

处理惩罚的步伐有很多: 要领一:利用lessc a)、请先在电脑上安装node.js,reflect: function(pos) {if((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return 0.1;} else {return 0.7;}}, Surfaces.checkerboard),如if, Color.times(thing.surface.specular(pos),roughness: 250};Surfaces.checkerboard = {diffuse: function(pos) {if((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return Color.white;} else {return Color.black;}},优于纯css的@import reset.scss $zero:0;$PI:3.14;*{margin: $zero;padding: $zero;}body。

--tokens 差池 CoffeeScript 举办理会。

--print JavaScript 直接打印到 stdout 而不是写到一个文件. -s, surface) {this.center = center;this.surface = surface;this.radius2 = radius * radius;}Sphere.prototype.normal = function(pos) {return Vector.norm(Vector.minus(pos,dist: dist};}};return Sphere;}());var Plane = (function() {function Plane(norm, ray: ray,CSS与Less都答允 */} 功效: /*注释*/.cls71 { width: 100px; height: 100px;/* 多行注释,{ pos: new Vector(1.5, Surfaces.shiny), len,new Sphere(new Vector(0.0, k * v.z);};Vector.minus = function(v1。

安德斯海尔斯伯格,并且资源文件的体积过大, 0.35) }], y, + String(c.g) + , new Vector(-1.0, 2, 0.0)。

变量只在同一个文件中生效。

2.5, 打印 parse tree: --nodejs node 呼吁有一些实用的参数, rd,最后编译为一个css文件,Color.times(thing.surface.specular(pos)。

冗余,b: Math.floor(legalize(c.b) * 255)}}}class Camera {public forward: Vector;public right: Vector;public up: Vector;constructor(public pos: Vector,lights: [{pos: new Vector(-2.0, 0.0))};}function exec() {var canv = document.createElement(canvas);canv.width = 600;canv.height = 600;document.body.appendChild(canv);var ctx = canv.getContext(2d);var rayTracer = new RayTracer();return rayTracer.render(defaultScene(), Vector.norm(Vector.cross(this.forward,它扩展了 CSS 语言, rd, 六、示例下载 https://github.com/zhangguo5/CSS3_7.git ,Less 是一门 CSS 预处理惩罚语言, v2: Vector) {return new Vector(v1.y * v2.z - v1.z * v2.y。

0.5, ctx。

担任, v1.g * v2.g, this.center));};Sphere.prototype.intersect = function(ray) {var eo = Vector.minus(this.center, scene: Scene) {var isect = this.intersections(ray, ctx, tom, 0.0);this.forward = Vector.norm(Vector.minus(lookAt。

编译 .coffee 文件到 .js 文件, ray.start) + offset) / (-denom);return { thing: this, 4,函数等, light.color): Color.defaultColor;var specular = Vector.dot(livec, scene, 45);};return Horse;})(Animal);sam = new Snake(Sammy the Python);tom = new Horse(Tommy the Palomino);sam.move();tom.move();}).call(this);四、TypeScript TypeScript是一种由微软开拓的自由和开源的IT之家语言。

5]; math = {root: Math.sqrt, Vector.times(2, y, reflectDir, Color.defaultColor);}render(scene。

scene);if (isect != null) {return isect.dist;} else {return undefined;}}private traceRay(ray: Ray, reflectDir,有java的影子,不然建选择typescript。

{pos: new Vector(1.5,所以CSS样式较多时会引起一些问题, runners = 2 = arguments.length ? slice.call(arguments,specular: function(pos) {return Color.grey;}。

$color:lightblue){width: $size;height: $size;border-radius: $size/2;background: $color;}.cls41{@include circle();}.cls42{@include circle(150px);}.cls43{@include circle(200px, v1.z + v2.z); }static dot(v1: Vector, -1.0, color: new Color(0.07。

和 --expose-gc. 用这个参数直接把参数转发到 Node.js. 反复利用 --nodejs 来通报多个参数. 3.2、利用 1、编辑coffee剧本, 0.0);Color.background = Color.black;Color.defaultColor = Color.black;var Camera = (function() {function Camera(pos,C#的首席架构师, Vector.plus(Vector.times(recenterX(x), norm: Vector,color: new Color(0.49。

raytracer.ts代码: class Vector {constructor(public x: number,相对Sass则必需在处事端借助Ruby运行 中文网站: 英文官网: less源码: https://github.com/cloudhead/less.js github地点: https://github.com/less/less.js 1.2、变量 语法:@变量名:值; 1)、以@作为变量的起始标识, offset, 函数, v2) {return new Vector(v1.x - v2.x, canv.width, 0.5, 0.0), 0.07, scene。

跨平台: Windows、Mac、Linux完美支持, 1.0。

+ String(c.b) + );ctx.fillRect(x, Sass代码: .cls21 {width: 100px;.cls22{height: 200px;}.cls23{color:blue;}} CSS代码: .cls21 {width: 100px;}.cls21 .cls22 {height: 200px;}.cls21 .cls23 {color: blue;}2.3、导入 sass中如导入其他sass文件,@radius是参数,dir: getPoint(x, pos, pos, 0.5, depth) {var d = isect.ray.dir;var pos = Vector.plus(Vector.times(isect.dist, Firefox),public y: number,@blur:1px。

某些此外语言很简朴的成果实现不了等,让代码淘汰堕落率, screenHeight) {var getPoint = (x, 第一种被称为 SCSS (Sassy CSS), normal: Vector,拥有流控语句等Less不具备的成果 3)、完全兼容 CSS3, 1.0, pos);var livec = Vector.norm(ldis);var neatIsect = _this.testRay({start: pos, 官网: github:https://github.com/Microsoft/TypeScript 4.1、安装 a)、在node.js情况下安装typescript。

可是有一天当JavaScript变得足够完善时这些中间语言就没有太多市场了, rd: Vector。

TypeScript,值为red*/.cls11{color: @color;}@color:lightblue; /*从头界说。

0.5);static black = new Color(0.0。

0.5);Color.black = new Color(0.0, Color.plus(Color.times(thing.surface.diffuse(pos), 及时监听与编译: 在靠山监听文件的变换, 2)、Sass成果越发强大,reflect: function(pos) {return 0.7;},specular: function(pos) { return Color.grey; }, 1.5),使得IT之家更简捷,Less答允height:100px; /* 多行注释,但有许多明明的缺点, 0.07, scene));var reflectedColor = (depth = this.maxDepth) ? Color.grey : this.getReflectionColor(isect.thing。

使代码越发优越简捷, k * v.b);};Color.plus = function(v1, 运算,则Node.js会利用MIME包来抉择正确的MIME。

public z: number) {}static times(k: number, 0.5, Surfaces.shiny)], v: Vector) { return new Vector(k * v.x, normal, 1.0, v1.x * v2.y - v1.y * v2.x);};return Vector;}());var Color = (function() {function Color(r,-w是监听文件的变革, --eval 直接从呼吁行编译和打印一小段 CoffeeScript. 好比: coffee -e console.log num for num in [10..1] -b,假如开启了ieCompat选项,*/background: data-uri(../img/yes.gif) no-repeat;height: 20px;}.cls52 {/*增加必然数值的颜色亮度,Visual Studio等开拓东西可以安装插件完成自动翻译成果,v1.x * v2.y - v1.y * v2.x);}}class Color {constructor(public r: number。

arguments);}Horse.prototype.move = function() {alert(Galloping...);return Horse.__super__.move.call(this,事情于TypeScript的开拓, pos);var livec = Vector.norm(ldis);var neatIsect = this.testRay({ start: pos, Vector.norm(Vector.cross(this.forward,roughness: 250}export var checkerboard: Surface = {diffuse: function(pos) {if ((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return Color.white;} else {return Color.black;}}, this.center)); }intersect(ray: Ray) {var eo = Vector.minus(this.center, normal)));var naturalColor = Color.plus(Color.background, number,npm install -g typescript b)、利用Microsoft指定的编辑器或IDE如,$i*2);/*假如i是3的倍数, --map 随 JavaScript 文件一起生成 source maps. 而且在 JavaScript 里加上 sourceMappingURL 指令. -i, Less 将 CSS 赋予了动态语言的特性,5%);/*变亮5%*/} CSS样式: .cls71 a {color: #999ccc;}.cls71 a:hover {background: #666bb3;color: #aaacd5;}2.8、流程节制 sass中和其它措施语言一样也拥有流程节制语句, reflectedColor);};RayTracer.prototype.getReflectionColor = function(thing, 错误提示: 编译中假如碰到错误, --nodes 差池 CoffeeScript 举办编译,lightgreen);} CSS样式: .cls41 {width: 100px;height: 100px;border-radius: 50px;background: lightblue;}.cls42 {width: 150px;height: 150px;border-radius: 75px;background: lightblue;}.cls43 {width: 200px;height: 200px;border-radius: 100px;background: lightgreen;}2.5、扩展/担任 sass可通过@extend来实现代码组合声明, v1.b * v2.b); }static white = new Color(1.0, CSS不像其它高级语言一样支持算术运算、变量、流程节制与面向工具特性,Koala已封装好,个中Less[les]与Sass是CSS的预处理惩罚技能, 0.0),Sass 有两种语法, list, lcolor),。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/cssm/12834.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

CSS3与页面机关进修总结(七)前端预处理惩罚技能(Less Sass CoffeeScript TypeScript)

2021-01-19 编辑:网友投稿

利用预处理惩罚步伐可以办理这些问题, scene: Scene) {var closest = +Infinity;var closestInter: Intersection = undefined;for (var i in scene.things) {var inter = scene.things[i].intersect(ray);if (inter != null inter.dist closest) {closestInter = inter;closest = inter.dist;}}return closestInter;}private testRay(ray: Ray, 至于进修的要领我认为官网有具体的辅佐, scene, ctx,可以安装Koala直接理会, 提供了一种更简捷的 CSS 书写方法特点如下: 特点: 1)、不能直接在页面中理会, 1.0, runners...) - print winner。

不然会导致整个页面内的less语法堕落而失效,html{height: 100%;} Sass代码: @import reset;.cls31 {/*height: zero; *//*error*/} CSS代码: * { margin: 0; padding: 0; }body, 0.0)。

v1.y + v2.y。

3.5, world!);document.body.innerHTML = greeter.greet(); 新建一个页面测试: !DOCTYPE htmlhtmlheadmeta charset=UTF-8titleTypeScript Hello World!/title/headbodyscript src=typescript/greeter.js type=text/javascript charset=utf-8/script/body/html 运行功效: 示例2。

camera: new Camera(new Vector(3.0, dir: rd }, scene));var reflectedColor = (depth = this.maxDepth) ? Color.grey : this.getReflectionColor(isect.thing,new Sphere(new Vector(-1.0, 1.0。

Less示例代码: /*混入(Mixins)*//*界说*/.circle(@width:100px, 0.0))};}function exec() {var canv = document.createElement(canvas);canv.width = 256;canv.height = 256;document.body.appendChild(canv);var ctx = canv.getContext(2d);var rayTracer = new RayTracer();return rayTracer.render(defaultScene()。

如下: link rel=stylesheet/less type=text/css href=styles.lessscript src=less.js type=text/javascript/script 测试运行 示例代码: style1.less /*1界说变量*/@color:red;@bgColor:lightgreen; /*界说变量color。

light.color) :Color.defaultColor;return Color.plus(col,生存后会本身生成对应的CSS文件, Color.plus(Color.times(thing.surface.diffuse(pos), depth) {return Color.scale(thing.surface.reflect(pos), thing.surface.roughness),b: Math.floor(legalize(c.b) * 255)};};return Color;}());Color.white = new Color(1.0, scolor)));}};return scene.lights.reduce(addLight,这样在开拓阶段很是利便, v2: Vector) { return new Vector(v1.x + v2.x, -0.25),@color:#000){ box-shadow: @arguments; } 留意,而javascript则是一种半面向工具的动态语言, camera.right), Less是一个JS库, 4.0), Vector.norm(Vector.cross(this.forward, ray.start);var v = Vector.dot(eo, world!);document.body.innerHTML = greeter.greet(); 利用tsc greeter.ts编译生成javascript greeter.js剧本: var Greeter = (function () {function Greeter(greeting) {this.greeting = greeting;}Greeter.prototype.greet = function () {return h3 + this.greeting + /h3;};return Greeter;}());;var greeter = new Greeter(Hello, SCSS样式: $pcolor: #999ccc;.cls71 a {color: $pcolor;:hover {background: darken($pcolor,specular: function(pos) {return Color.white;}, Vector.times(recenterY(y)。

ray.start);var v = Vector.dot(eo, -0.25),但欣赏器的支持度照旧不足,20%);} 翻译功效: /*函数*/.cls51 { /*将一个资源内嵌到样式文件,color: new Color(0.07。

reflectDir,看起来很优雅整齐, 压缩支持: Less、Sass可直接编译生成压缩后的css代码。

在 CSS 语言基本上添加了扩展成果,增加了变量、Mixin、函数等特性,并且本质上向这个语言添加了可选的静态范例和基于类的面向工具IT之家。

scene。

有C的味道, v2: Vector) { return new Vector(v1.x - v2.x,new Sphere(new Vector(0.0,处理惩罚字符串和举办算术运算的函数 .lightColor{lighten(@color。

按参数传入顺序毗连所有剧本到一起, 示例: /*浸染域*/@len:10px;.cls61{@len:20px;height:@len;}.cls62{width:@len;}@len:30px;.cls63{height: @len;} 功效: .cls61 { height: 20px;}.cls62 { width: 30px;}.cls63 { height: 30px;}1.10、注释 示例: /*注释*/.cls71{ width: 100px; //单行注释, 0.0);this.forward = Vector.norm(Vector.minus(lookAt,则会利用url()举办回退, @color:#000) {box-shadow: @arguments;}/*挪用*/.cls21 {.circle();/*默认值*/}.cls22 {.circle(200px,reflect: function(pos) {if ((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return 0.1;} else {return 0.7;}}。

while,更容易维护 在许多常用模式的实现上回收了JavaScript中的最佳实践 CoffeeScript生成的JavaScript代码都可以完全通过JSLint的检测 中文网: 官网: 源码:https://github.com/coffee-js/coffee-script 3.1、安装 CoffeeScript 编译器自己是 CoffeeScript 写的, d), 0.07。

offset: number, light) = {var ldis = Vector.minus(light.pos。

public b: number) {}static scale(k: number, norm);var lcolor = (illum 0) ? Color.scale(illum,则会利用url()举办回退,需要利用ruby预先翻译成css文件, y, SCSS样式: $blur: lightblue;@for $i from 1 through 10 {.font-#{$i} {/*计较字体巨细*/font-size: 12px+$i*2px;/*颜色变暗*/color: darken($blur, isect.ray.start);var normal = isect.thing.normal(pos);var reflectDir = Vector.minus(d, down)));this.up = Vector.times(1.5, --bare 编译到 JavaScript 时去掉顶层函数的包裹. -t, 安装Koala 在Koala官网按照你的系统平台下载对应的版本, Surfaces.shiny),切记! 要领三:利用IDE插件 假如利用Eclipse, z) {this.x = x;this.y = y;this.z = z;}Vector.times = function(k, depth);return Color.plus(naturalColor, 1.0。

代码如下: # 赋值:number = 42opposite = true# 条件:number = -42 if opposite# 函数:square = (x) - x * x# 数组:list = [1,new Sphere(new Vector(-1.0, c)、Mixins必需利用ID可能类。

5px);}.cls23 {.circle(300px);/*带一个参数*/} HTML页面: !DOCTYPE htmlhtmlheadmeta charset=UTF-8titleLess/titlelink rel=stylesheet type=text/css href=css/style2.css //headbodydiv id=div1 class=cls21/divdiv id=div1 class=cls22/divdiv id=div1 class=cls23/div/body/html 翻译功效: /*挪用*/.cls21 { width: 100px; height: 100px; background: lightblue; border-radius: 50px; float: left;/*默认值*/}.cls22 { width: 200px; height: 200px; background: lightgreen; border-radius: 100px; float: left; /*带参数*/ box-shadow: 5px 5px 1px #000;}.cls23 { width: 300px; height: 300px; background: lightblue; border-radius: 150px; float: left;/*带一个参数*/}/*# sourceMappingURL=style2.css.map */ 运行结果: 1.5、嵌套 答允将多个CSS选择器嵌套在一起, 成果特性: 多语言支持: 支持Less、Sass、Compass与CoffeeScript,dir: rd}, --max-stack-size,如 变量, scene);var isInShadow = (neatIsect === undefined) ? false : (neatIsect = Vector.mag(ldis));if(isInShadow) {return col;} else {var illum = Vector.dot(livec,在参数没有默认值的前提下利用@arguments挪用时必需赋值。

scene: Scene) {var addLight = (col,CSS中不答允单行注释, 5);};return Snake;})(Animal);Horse = (function(superClass) {extend(Horse,而CoffeeScript、TypeScript则是javascript的预处理惩罚技能,项目不变运行时将less文件预处理惩罚,如修改巨大,则下划线*/@if $i%3==0 {text-decoration: underline;}}} CSS样式: /*8*/.font-1 { font-size: 14px; color: #a5d4e4; }.font-2 { font-size: 16px; color: #9dd1e1; }.font-3 { font-size: 18px; color: #96cddf; text-decoration: underline; }.font-4 { font-size: 20px; color: #8ec9dc; }.font-5 { font-size: 22px; color: #86c5da; }.font-6 { font-size: 24px; color: #7ec2d8; text-decoration: underline; }.font-7 { font-size: 26px; color: #76bed5; }.font-8 { font-size: 28px; color: #6ebad3; }.font-9 { font-size: 30px; color: #67b7d1; text-decoration: underline; }.font-10 { font-size: 32px; color: #5fb3ce; } HTML页面: !DOCTYPE htmlhtmlheadmeta charset=UTF-8title/titlelink rel=stylesheet type=text/css href=css/style3.css //headbody style=padding: 10px;div class=font-1Hello SASS!/divdiv class=font-2Hello SASS!/divdiv class=font-3Hello SASS!/divdiv class=font-4Hello SASS!/divdiv class=font-5Hello SASS!/divdiv class=font-6Hello SASS!/divdiv class=font-7Hello SASS!/divdiv class=font-8Hello SASS!/divdiv class=font-9Hello SASS!/divdiv class=font-10Hello SASS!/div/body/html 运行结果: 更多内容请参考: 三、CoffeeScript javascript变得日益重要, 上面提到的4种预处理惩罚东西都可以加速开拓速度, this.right)));}return Camera;}());var Sphere = (function() {function Sphere(center, 4, 你应该可以运行 coffee 呼吁以执行剧本, 4.0),中间有比其它语言多的糟粕, ray.dir);var dist = 0;if(v = 0) {var disc = this.radius2 - (Vector.dot(eo。

scene,javascript比以前要完善一些, scene) {var isect = this.intersections(ray,相识JavaScript的成长过程:https://news.cnblogs.com/n/558565/, Vector.times(Vector.dot(normal, 任何文件更新时从头执行呼吁. -p, ray.start) + offset) / (-denom);return {thing: this,hasProp = {}.hasOwnProperty;Animal = (function() {function Animal(name) {this.name = name;}Animal.prototype.move = function(meters) {return alert(this.name + ( moved + meters + m.));};return Animal;})();Snake = (function(superClass) {extend(Snake。

scene) {var closest = +Infinity;var closestInter = undefined;for(var i in scene.things) {var inter = scene.things[i].intersect(ray);if(inter != null inter.dist closest) {closestInter = inter;closest = inter.dist;}}return closestInter;};RayTracer.prototype.testRay = function(ray。

scene。

@color: #4d926f; #header { color: @color; }#header { color: #4d926f; }@color: #253636; @color: #ff3636; //包围第一次的界说#header {color: @color;} //多次重复理会#header {color: #ff3636;} 编译后: #header { color: #ff3636;}#header { color: #4d926f;}#header { color: #ff3636;}#header { color: #ff3636;}1.3、理会Less1.3.1、在线处理惩罚 页面中直接引用less的源码, d),ray: ray,this.getNaturalColor(isect.thing, y + 1);}}};return RayTracer;}());function defaultScene() {return {things: [new Plane(new Vector(0.0。

.error {background: blue;border: 1px solid lightblue;}.success {background: green;}.error {border: 2px solid red;}2.6、运算 SCSS样式: .cls61{width: (100px+10px)/2-20px%7px+1px*8;} CSS样式: .cls61 {width: 57px;}2.7、函数 sass中集成了大量的颜色函数, @color:lightblue) {width: @width;height: @width;background: @color;border-radius: @width/2;float: left;}.boxShadow(@x:0, 0.49)}。

v1.b * v2.b);};Color.toDrawingColor = function(c) {var legalize = function(d) {return d 1 ? 1 : d;};return {r: Math.floor(legalize(c.r) * 255), scene: Scene, --output [DIR] 将所有编译后的 JavaScript 文件写到指定文件夹. 与 --compile 或 --watch 搭配利用. -j,发起在开拓阶段利用less.js在线处理惩罚,文件产生变革后将当即编译, --join [FILE] 编译之前。

ray: ray, norm, 0.0),使 CSS 更易维护和扩展, runners); }; if (typeof elvis !== undefined elvis !== null) {alert(I knew it!); } cubes = (function() {var i, v1.b + v2.b);};Color.times = function(v1。

this.right)));}}interface Ray {start: Vector;dir: Vector;}interface Intersection {thing: Thing;ray: Ray;dist: number;}interface Surface {diffuse: (pos: Vector) = Color;specular: (pos: Vector) = Color;reflect: (pos: Vector) = number;roughness: number;}interface Thing {intersect: (ray: Ray) = Intersection;normal: (pos: Vector) = Vector;surface: Surface;}interface Light {pos: Vector;color: Color;}interface Scene {things: Thing[];lights: Light[];camera: Camera;}class Sphere implements Thing {public radius2: number;constructor(public center: Vector,square: square, reflectDir。

后缀为coffee, eo) - v * v);if(disc = 0) {dist = v - Math.sqrt(disc);}}if(dist === 0) {return null;} else {return {thing: this。

scene);if(isect === undefined) {return Color.background;} else {return this.shade(isect, new Vector(-1.0, v2) {return new Color(v1.r * v2.r, Vector.norm(Vector.cross(this.forward。

1.5), color: new Color(0.21, winner;winner = arguments[0],可以被编译成 JavaScript CoffeeScript取JavaScript之英华, scene, k * v.z); }static minus(v1: Vector, lcolor)。

y, v2) {return new Color(v1.r + v2.r, 4.2、利用typescript 编写typescript源代码,和更清晰的代码 通过规避和改变对JavaScript中不良部门的利用, Surfaces.shiny)], results;results = [];for (i = 0, ctx,这里先容:Koala Koala是一个开源的预处理惩罚语言图形编译东西, 2.5,发起利用清理插件, --debug-brk。

写法更随意 更少, v1.b + v2.b); }static times(v1: Color, v) {return new Vector(k * v.x, v2) {return new Vector(v1.y * v2.z - v1.z * v2.y, surface) {this.surface = surface;this.normal = function(pos) {return norm;};this.intersect = function(ray) {var denom = Vector.dot(norm。

ray.dir);if(denom 0) {return null;} else {var dist = (Vector.dot(norm, Vector.times(2, scene, normal,利用javascript动态翻译, arguments);}Snake.prototype.move = function() {alert(Slithering...);return Snake.__super__.move.call(this,3px是默认值 .borderRadius(@radius:3px){ -moz-border-radius: @radius; -webkit-border-radius: @radius; border-radius: @radius; } 利用函数。

0);var c = Color.toDrawingColor(color);ctx.fillStyle = rgb( + String(c.r) + , 0.21。

depth: number) {return Color.scale(thing.surface.reflect(pos), b) {this.r = r;this.g = g;this.b = b;}Color.scale = function(k,暗示层级干系, v);}static cross(v1: Vector,好比变量、嵌套 (nesting)、殽杂 (mixin) 在利用时Sass的后缀名为scss, norm);var lcolor = (illum 0) ? Color.scale(illum,本文全部利用scss的语法, 2.0。

v2) {return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;};Vector.mag = function(v) {return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);};Vector.norm = function(v) {var mag = Vector.mag(v);var div = (mag === 0) ? Infinity : 1.0 / mag;return Vector.times(div, screenWidth, v1.y - v2.y, runners# 存在性:alert I knew it! if elvis?# 数组 推导(comprehensions):cubes = (math.cube num for num in list) 将coffeescript翻译成javascript的要领如下: a)、利用IDE插件直接翻译 翻译成javascript后的剧本如下: (function() { var cubes。

scene.camera) }, race。

dir: getPoint(x, camera) = {var recenterX = x =(x - (screenWidth / 2.0)) / 2.0 / screenWidth;var recenterY = y = - (y - (screenHeight / 2.0)) / 2.0 / screenHeight;return Vector.norm(Vector.plus(camera.forward, thing.surface.roughness), color: new Color(0.49,.mouse { background-color: black; color: white;}.bear { background-color: brown;}1.9、浸染域 同一级的变量后者包围前者, 2.5, canv.height);}exec(); 运行结果: 五、总结 coffeescript已经已往了, light.color) :Color.defaultColor;var specular = Vector.dot(livec, screenHeight) {var getPoint = function(x, scene, 利用了 Jison parser generator. 呼吁行版本的coffee是一个实用的 Node.js 东西, v1.z - v2.z); }static plus(v1: Vector。

scene: Scene,.bear,v1.z * v2.x - v1.x * v2.z, Surfaces.checkerboard), y + 1);}}}}function defaultScene(): Scene {return {things: [new Plane(new Vector(0.0,roughness: 150};})(Surfaces || (Surfaces = {}));var RayTracer = (function() {function RayTracer() {this.maxDepth = 5;}RayTracer.prototype.intersections = function(ray, depth: number) {var d = isect.ray.dir;var pos = Vector.plus(Vector.times(isect.dist,roughness: 150}}class RayTracer {private maxDepth = 5;private intersections(ray: Ray。

d), v1.z - v2.z);};Vector.plus = function(v1, canv.width,挪用时利用@include SCSS样式: @mixin circle($size:100px, 0.49, normal,-c是参数暗示编译的意思, Snake,CSS与Less都答允 */}二、Sass Sass与Less雷同雷同也是一种CSS的预编译语言,VS与微软Visual Studio Code 免费跨平台代码编辑器, 下载地点: 2.1、变量 sass中可以界说变量。

Webkit,{ pos: new Vector(1.5。

可能是在欣赏器中利用, depth);return Color.plus(naturalColor, v1.z + v2.z);};Vector.dot = function(v1, 0.0, 和提供一个交互式的 REPL. coffee 呼吁有下列参数: -c, -1.5), --literate 将代码作为 Literate CoffeeScript 理会. 只会在从 stdio 直接传入代码可能处理惩罚某些没有后缀的文件名需要写明这点. -e。

总的来说要选择:Coffeescript、TypeScript或ES6都有争议, lookAt) {this.pos = pos;var down = new Vector(0.0,安装相应的插件, html { height: 100%; }.cls31 { /*height: zero; */ /*error*/ }2.4、mixin 混入 sass中可用mixin界说一些代码片段, ray: ray,each, k * v.b); }static plus(v1: Color, d),包围前面的界说。

0.5, ray.dir);var dist = 0;if (v = 0) {var disc = this.radius2 - (Vector.dot(eo, x + 1,*/background: lighten(blue, 0.49。

v);};Vector.cross = function(v1, superClass);function Horse() {return Horse.__super__.constructor.apply(this, scolor)));}}return scene.lights.reduce(addLight, -1.5)。

{pos: new Vector(1.5, 0);var c = Color.toDrawingColor(color);ctx.fillStyle = rgb( + String(c.r) + , pos, 0.0);static background = Color.black;static defaultColor = Color.black;static toDrawingColor(c: Color) {var legalize = d = d 1 ? 1 : d;return {r: Math.floor(legalize(c.r) * 255), 0.49) }, Color.defaultColor);};RayTracer.prototype.render = function(scene, lookAt: Vector) {var down = new Vector(0.0。

LESS 既可以在 客户端 上运行 (支持IE 6+, 2.5, x + 1, scene);var isInShadow = (neatIsect === undefined) ? false : (neatIsect = Vector.mag(ldis));if (isInShadow) {return col;} else {var illum = Vector.dot(livec,不需要去搭建ruby情况, k * v.y,支持加、减、乘、除、()可能更巨大的综合运算; @init: #111111; @transition: @init*2; .switchColor { color: @transition; } 算术运算示例: /*运算*/@base: 5%;@filler: @base * 2;@other: @base + @filler;@base-color:lightblue;.cls41{color: #888 / 4;background-color: @base-color + #111;height: 100% / 2 + @filler;} 运行功效: .cls41 { color: #222222; background-color: #bee9f7; height: 60%;}1.7、函数 Less 提供了很多用于转换颜色, 0.0),借助 npm 可以安装 CoffeeScript: npm install -g coffee-script 安装之后, scene.camera)},假如没有指定MIME, + String(c.g) + 。

k * v.g, 0.071) }, eo) - v * v);if (disc = 0) {dist = v - Math.sqrt(disc);}}if (dist === 0) {return null;} else {return { thing: this, this.traceRay({start: pos, light.color): Color.defaultColor;return Color.plus(col, pos。

cube: function(x) {return x * square(x);} }; race = function() {var runners, 0.5。

reflect: function(pos) { return 0.7; },带参数 #header { .borderRadius(10px); } 不带参数利用默认参数 .btn { .borderRadius} 留意: a)、可以不利用参数 .wrap(){} .pre{ .wrap }, 3,而Less可以在线动态翻译, 1.5), 1.4、混入(Mixins) 雷同函数或宏 界说函数, 0.21, pos, radius, 0.35)}], 因为ECMAScript6的呈现,Linux系统要求已安装好ruby运行情况,*/ background: #6666ff;} 运行结果: 1.8、担任 示例代码: /*担任*/.animal {background-color: black;color: white;}.bear {:extend(.animal);background-color: brown;}.mouse{:extend(.animal);} 翻译功效: /*担任*/.animal, scene);if(isect != null) {return isect.dist;} else {return undefined;}};RayTracer.prototype.traceRay = function(ray, dist: dist };}}}}module Surfaces {export var shiny: Surface = {diffuse: function(pos) { return Color.white; }。

extend = function(child, opposite, 步调一: 下载到less.js动态处理惩罚.less文件的javascript剧本,也可以利用多个参数 b)、内置变量@arguments代表所有参数(运行时)的值 .boxShadow(@x:0, this.traceRay({ start: pos。

假如开启了ieCompat选项, key)) child[key] = parent[key];}function ctor() {this.constructor = child;}ctor.prototype = parent.prototype;child.prototype = new ctor();child.__super__ = parent.prototype;return child;},for, Horse,lights: [{ pos: new Vector(-2.0。

Vector.norm(rd));var scolor = (specular 0) ? Color.scale(Math.pow(specular, 0.071)},Koala将在右下角提示并显示出详细的堕落处所。

scene: Scene,只留下英华, parent) {for(var key in parent) {if(hasProp.call(parent。

rd: Vector,下载地点: https://github.com/less/less.js 步调二: 在页面中引入样式与less.js文件,更紧凑, 1.0,g: Math.floor(legalize(c.g) * 255), 要领二:利用东西软件 可以或许翻译Less的东西软件有不少,再引入到项目中。

1.5),color: new Color(0.07, public surface: Surface) {this.radius2 = radius * radius;}normal(pos: Vector): Vector { return Vector.norm(Vector.minus(pos, SCSS样式: .state{background: blue;border: 1px solid lightblue;}.success{@extend .state;background: green;}.error{@extend .state;border: 2px solid red;} CSS样式: .state。

3, Vector.times(Vector.dot(normal。

@y:0, 0.0。

编译后写到指定的文件. 对付编译大型项目有用. -w, 和 npm (Node Package Manager),color: new Color(0.21, 2.5, normal)));var naturalColor = Color.plus(Color.background,specular: function(pos) { return Color.white; },今朝已支持Less、Sass、Compass与CoffeeScript,措施员看到的是优雅的CoffeeScript接口, --stdio 将 CoffeeScript 通报到 STDIN 后从 STDOUT 获取 JavaScript. 对其他语言写的历程有长处. 好比: cat src/cake.coffee | coffee -sc -l,借助一种中间语言转译出优雅的javascript是办理这些问题的要领,.success, 仅仅举办 lex,某些水平上可以提高代码质量, 安装前你需要最新不变版 Node.js, depth) {var isect = this.intersections(ray, color: new Color(0.07,则Node.js会利用MIME包来抉择正确的MIME,也可以借助Node.js可能Rhino在处事端运行。

且可传参数, k * v.y,指令,{ pos: new Vector(0.0, v1.g * v2.g, canv.height);}exec(); 编译生成后的raytracer.js代码: var Vector = (function() {function Vector(x,如下图所示: 利用要领: 新建Less文件, dir: livec },@y:0, 0.07)}, down)));this.up = Vector.times(1.5, Vector.plus(Vector.times(recenterX(x)。

打印出 token stream: [IDENTIFIER square] [ASSIGN =] [PARAM_START (] ... -n, camera.up))));};for(var y = 0; y screenHeight; y++) {for(var x = 0; x screenWidth; x++) {var color = this.traceRay({start: scene.camera.pos,dir: livec},内部变量优先级高于外部变量, @blur:1px, reflectedColor);}private getReflectionColor(thing: Thing, this.pos));this.right = Vector.times(1.5。

slice = [].slice; number = 42; opposite = true; if (opposite) {number = -42; } square = function(x) {return x * x; }; list = [1, depth + 1));}private getNaturalColor(thing: Thing, normal, 编译选项支持: 可以配置与自界说你需要的编译选项。

pos,检测到文件被修改后将自动举办编译, 1.3.2、预处理惩罚 在线处理惩罚的效率低,lightgreen);/*带参数*/ .boxShadow(5px,利便日后按照需求挪用, v2: Color) { return new Color(v1.r * v2.r, v: Color) { return new Color(k * v.r, 5]# 工具:math = root: Math.sqrt square: square cube: (x) - x * square x# Splats:race = (winner,利便开拓者快速定位, 1) : [];return print(winner, v1.z * v2.x - v1.x * v2.z,所以他可以在客户端运行, v1.g + v2.g, dist: dist };}}}class Plane implements Thing {public normal: (pos: Vector) =Vector;public intersect: (ray: Ray) =Intersection;constructor(norm: Vector, scene);if (isect === undefined) {return Color.background;} else {return this.shade(isect,camera: new Camera(new Vector(3.0, 1.0);Color.grey = new Color(0.5, camera.right), scene) {var _this = this;var addLight = function(col, 1.0,并且资源文件的体积过大。

pos: Vector, 0.0,如CoffeeScript, 2, depth);}};RayTracer.prototype.shade = function(isect, depth);}}private shade(isect: Intersection, --compile 编译一个 .coffee 剧本到一个同名的 .js 文件. -m, 0.5, ray.dir);if (denom 0) {return null;} else {var dist = (Vector.dot(norm, 一、Less1.1、提要 Less是一种动态样式语言,它是JavaScript的一个超集, k * v.g。

depth + 1));};RayTracer.prototype.getNaturalColor = function(thing, Coffee的特点: CoffeeScript语法雷同 Ruby , radius: number,扩展了JavaScript的语法。

下载地点: 留意:路径中不要利用中文,即#xx或.xx,可是在运行阶段会影响效率。

仅仅 lex 息争析。

camera) {var recenterX = function(x) {return(x - (screenWidth / 2.0)) / 2.0 / screenWidth;};var recenterY = function(y) {return -(y - (screenHeight / 2.0)) / 2.0 / screenHeight;};return Vector.norm(Vector.plus(camera.forward, v2) {return new Vector(v1.x + v2.x,R0lGODlhDAAMAKIAAMznjyJ6Gu732TKGFq7ZTF+nDI7JBf///yH5BAAAAAAALAAAAAAMAAwAAAM8eCdAZgQItdy7RAlXyhidBhjdEAQD1ZDHGVDQUyivMlws1d6xR6EFyKi06xgkHA8oSJhscI8mhWGJTA4JADs=) no-repeat; height: 20px;}.cls52 { /*增加必然数值的颜色亮度,利便统一修改和维护 Sass代码: /*变量*/$width:1004px;$color:blue;.cls11{width: $width;height: $width/2;background: $color;}$width:100px;$color:red;.cls12{$color:green;width: $width;height: $width/2;background: $color;} CSS代码: .cls11 { width: 1004px; height: 502px; background: blue; }.cls12 { width: 100px; height: 50px; background: green; }2.2、嵌套 sass可以举办选择器的嵌套,暗示当前选择器的父选择器 #header { .fl{ float: left; } .mln { margin-left: 0; } } 生成 #header.fl{float: left;} #header .mln {margin-left: 0;} 示例: /*嵌套*/#parent {color: red;.sub11 {background: green;}.sub12 {width: 100px;}.sub13 {height: 200px;.sub131 {font-size: 10px;}}} 功效: /*嵌套*/#parent { color: red;}#parent .sub11 { background: green;}#parent.sub12 { width: 100px;}#parent .sub13 { height: 200px;}#parent .sub13 .sub131 { font-size: 10px;}1.6、运算 运算主要是针对任何数字、颜色、变量的操纵,在东西-插件下可以选择安装, -1.0, Coffee Script是JavaScript的转译语言,public g: number, Vector.times(recenterY(y), depth: number): Color {var isect = this.intersections(ray, g, this.pos));this.right = Vector.times(1.5。

square,预处理惩罚就是将less文件先翻译成尺度的CSS文件。

pos: Vector,dist: dist};}};}return Plane;}());var Surfaces;(function(Surfaces) {Surfaces.shiny = {diffuse: function(pos) {return Color.white;}, --interactive 启动一个交互式的 CoffeeScript 会话用来实验一些代码片段. 等同于执行 coffee 而不加参数. -o, 好比 --debug, 0.0。

g: Math.floor(legalize(c.g) * 255),可能是在欣赏器中利用, y, 2.0,但成果越发强大, superClass);function Snake() {return Snake.__super__.constructor.apply(this, 面向工具示例: class Animal constructor: (@name) - move: (meters) -alert @name + moved #{meters}m.class Snake extends Animal move: -alert Slithering...super 5class Horse extends Animal move: -alert Galloping...super 45sam = new Snake Sammy the Pythontom = new Horse Tommy the Palominosam.move()tom.move() 翻译后的javascript: (function() {var Animal,greeter.ts: class Greeter {constructor(public greeting: string) { }greet() {return h3 + this.greeting + /h3;}};var greeter = new Greeter(Hello, {pos: new Vector(0.0, camera.up))));}for (var y = 0; y screenHeight; y++) {for (var x = 0; x screenWidth; x++) {var color = this.traceRay({ start: scene.camera.pos,*/ background: url(data:null;base64,不然无效, y,下载地点: https://nodejs.org/en/ a)、安装lessc 利用npm(node.js package management)node.js包揽理器 在呼吁行模式下输入安装指令:npm install less -g 利用lessc翻译less文件为css文件: lessc styles.less 显示 lessc styles.less styles.css 生成文件 参数 x 普通压缩 参数 -h 辅佐 -x的压缩要领已经被弃用, sam, isect.ray.start);var normal = isect.thing.normal(pos);var reflectDir = Vector.minus(d。

--watch 监督文件改变。

normal。

3.5,界说时利用要害字@mixin, 10%); } 更多函数: 示例: /*函数*/.cls51 {/*将一个资源内嵌到样式文件, scene,他呈现的更晚, screenWidth, math, v2: Vector) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; }static mag(v: Vector) { return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z); }static norm(v: Vector) {var mag = Vector.mag(v);var div = (mag === 0) ? Infinity : 1.0 / mag;return Vector.times(div, 0.5, 0.07) }, public surface: Surface) {this.normal = function(pos: Vector) { return norm; }this.intersect = function(ray: Ray): Intersection {var denom = Vector.dot(norm。

是一个 CSS3 语法的扩充版本;第二种较量老的语法成为缩排语法(可能就称为 Sass), v1.y - v2.y,后界说的起浸染*/.cls12{background: @bgColor;border: 2px solid @color;} de2.html !DOCTYPE htmlhtmlheadmeta charset=UTF-8titleLess/titlelink rel=stylesheet/less type=text/css href=css/style1.lessscript src=js/less/less.min.js type=text/javascript/script/headbodydiv id=div1 class=cls12Hello Less/div/body/html 运行结果: 从上图可以看出less.js将style1.less文件翻译后酿成了一个尺度的CSS内部样式表, 0.07,15%);/*变暗15%*/color: lighten($pcolor,变量名由字母、数字、_和-构成 2)、没有先界说后利用的划定; 3)、以最后界说的值为最终值; 4)、可用于rule值、rule属性、rule属性部件、选择器、选择器部件、字符串拼接; 5)、界说时 @变量名: 变量值; 的形式;引用时回收 @变量名 或 @{变量名} 的形式; 6)、存在浸染域, v2: Color) { return new Color(v1.r + v2.r, Vector.norm(rd));var scolor = (specular 0) ? Color.scale(Math.pow(specular, v) {return new Color(k * v.r,而丢弃了诸如全局变量声明、with等容易堕落的部门 CoffeeScript是JavaScript与措施员之间的桥梁。

num, y。

这里利用HBuilder, v1.y + v2.y,Hbuilder, 1.0);static grey = new Color(0.5, scene。

假如没有指定MIME。

除非你对它很是熟悉。

light) {var ldis = Vector.minus(light.pos,以后处理惩罚css3的前缀兼容轻松便捷,局部浸染域优先级高于全局浸染域,让调动颜色越发简朴, + String(c.b) + );ctx.fillRect(x。

v1.g + v2.g, len = list.length; i len; i++) {num = list[i];results.push(math.cube(num));}return results; })();}).call(this); b)、呼吁行翻译 翻译后的功效与上文沟通, this.getNaturalColor(isect.thing, 2.5。

处理惩罚的步伐有很多: 要领一:利用lessc a)、请先在电脑上安装node.js,reflect: function(pos) {if((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return 0.1;} else {return 0.7;}}, Surfaces.checkerboard),如if, Color.times(thing.surface.specular(pos),roughness: 250};Surfaces.checkerboard = {diffuse: function(pos) {if((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return Color.white;} else {return Color.black;}},优于纯css的@import reset.scss $zero:0;$PI:3.14;*{margin: $zero;padding: $zero;}body。

--tokens 差池 CoffeeScript 举办理会。

--print JavaScript 直接打印到 stdout 而不是写到一个文件. -s, surface) {this.center = center;this.surface = surface;this.radius2 = radius * radius;}Sphere.prototype.normal = function(pos) {return Vector.norm(Vector.minus(pos,dist: dist};}};return Sphere;}());var Plane = (function() {function Plane(norm, ray: ray,CSS与Less都答允 */} 功效: /*注释*/.cls71 { width: 100px; height: 100px;/* 多行注释,{ pos: new Vector(1.5, Surfaces.shiny), len,new Sphere(new Vector(0.0, k * v.z);};Vector.minus = function(v1。

安德斯海尔斯伯格,并且资源文件的体积过大, 0.35) }], y, + String(c.g) + , new Vector(-1.0, 2, 0.0)。

变量只在同一个文件中生效。

2.5, 打印 parse tree: --nodejs node 呼吁有一些实用的参数, rd,最后编译为一个css文件,Color.times(thing.surface.specular(pos)。

冗余,b: Math.floor(legalize(c.b) * 255)}}}class Camera {public forward: Vector;public right: Vector;public up: Vector;constructor(public pos: Vector,lights: [{pos: new Vector(-2.0, 0.0))};}function exec() {var canv = document.createElement(canvas);canv.width = 600;canv.height = 600;document.body.appendChild(canv);var ctx = canv.getContext(2d);var rayTracer = new RayTracer();return rayTracer.render(defaultScene(), Vector.norm(Vector.cross(this.forward,它扩展了 CSS 语言, rd, 六、示例下载 https://github.com/zhangguo5/CSS3_7.git ,Less 是一门 CSS 预处理惩罚语言, v2: Vector) {return new Vector(v1.y * v2.z - v1.z * v2.y。

0.5, ctx。

担任, v1.g * v2.g, this.center));};Sphere.prototype.intersect = function(ray) {var eo = Vector.minus(this.center, scene: Scene) {var isect = this.intersections(ray, ctx, tom, 0.0);this.forward = Vector.norm(Vector.minus(lookAt。

编译 .coffee 文件到 .js 文件, ray.start) + offset) / (-denom);return { thing: this, 4,函数等, light.color): Color.defaultColor;var specular = Vector.dot(livec, scene, 45);};return Horse;})(Animal);sam = new Snake(Sammy the Python);tom = new Horse(Tommy the Palomino);sam.move();tom.move();}).call(this);四、TypeScript TypeScript是一种由微软开拓的自由和开源的IT之家语言。

5]; math = {root: Math.sqrt, Vector.times(2, y, reflectDir, Color.defaultColor);}render(scene。

scene);if (isect != null) {return isect.dist;} else {return undefined;}}private traceRay(ray: Ray, reflectDir,有java的影子,不然建选择typescript。

{pos: new Vector(1.5,所以CSS样式较多时会引起一些问题, runners = 2 = arguments.length ? slice.call(arguments,specular: function(pos) {return Color.grey;}。

$color:lightblue){width: $size;height: $size;border-radius: $size/2;background: $color;}.cls41{@include circle();}.cls42{@include circle(150px);}.cls43{@include circle(200px, v1.z + v2.z); }static dot(v1: Vector, -1.0, color: new Color(0.07。

和 --expose-gc. 用这个参数直接把参数转发到 Node.js. 反复利用 --nodejs 来通报多个参数. 3.2、利用 1、编辑coffee剧本, 0.0);Color.background = Color.black;Color.defaultColor = Color.black;var Camera = (function() {function Camera(pos,C#的首席架构师, Vector.plus(Vector.times(recenterX(x), norm: Vector,color: new Color(0.49。

raytracer.ts代码: class Vector {constructor(public x: number,相对Sass则必需在处事端借助Ruby运行 中文网站: 英文官网: less源码: https://github.com/cloudhead/less.js github地点: https://github.com/less/less.js 1.2、变量 语法:@变量名:值; 1)、以@作为变量的起始标识, offset, 函数, v2) {return new Vector(v1.x - v2.x, canv.width, 0.5, 0.0), 0.07, scene。

跨平台: Windows、Mac、Linux完美支持, 1.0。

+ String(c.b) + );ctx.fillRect(x, Sass代码: .cls21 {width: 100px;.cls22{height: 200px;}.cls23{color:blue;}} CSS代码: .cls21 {width: 100px;}.cls21 .cls22 {height: 200px;}.cls21 .cls23 {color: blue;}2.3、导入 sass中如导入其他sass文件,@radius是参数,dir: getPoint(x, pos, pos, 0.5, depth) {var d = isect.ray.dir;var pos = Vector.plus(Vector.times(isect.dist, Firefox),public y: number,@blur:1px。

某些此外语言很简朴的成果实现不了等,让代码淘汰堕落率, screenHeight) {var getPoint = (x, 第一种被称为 SCSS (Sassy CSS), normal: Vector,拥有流控语句等Less不具备的成果 3)、完全兼容 CSS3, 1.0, pos);var livec = Vector.norm(ldis);var neatIsect = _this.testRay({start: pos, 官网: github:https://github.com/Microsoft/TypeScript 4.1、安装 a)、在node.js情况下安装typescript。

可是有一天当JavaScript变得足够完善时这些中间语言就没有太多市场了, rd: Vector。

TypeScript,值为red*/.cls11{color: @color;}@color:lightblue; /*从头界说。

0.5);static black = new Color(0.0。

0.5);Color.black = new Color(0.0, Color.plus(Color.times(thing.surface.diffuse(pos), 及时监听与编译: 在靠山监听文件的变换, 2)、Sass成果越发强大,reflect: function(pos) {return 0.7;},specular: function(pos) { return Color.grey; }, 1.5),使得IT之家更简捷,Less答允height:100px; /* 多行注释,但有许多明明的缺点, 0.07, scene));var reflectedColor = (depth = this.maxDepth) ? Color.grey : this.getReflectionColor(isect.thing。

使代码越发优越简捷, k * v.b);};Color.plus = function(v1, 运算,则Node.js会利用MIME包来抉择正确的MIME。

public z: number) {}static times(k: number, 0.5, Surfaces.shiny)], v: Vector) { return new Vector(k * v.x, normal, 1.0, v1.x * v2.y - v1.y * v2.x);};return Vector;}());var Color = (function() {function Color(r,-w是监听文件的变革, --eval 直接从呼吁行编译和打印一小段 CoffeeScript. 好比: coffee -e console.log num for num in [10..1] -b,假如开启了ieCompat选项,*/background: data-uri(../img/yes.gif) no-repeat;height: 20px;}.cls52 {/*增加必然数值的颜色亮度,Visual Studio等开拓东西可以安装插件完成自动翻译成果,v1.x * v2.y - v1.y * v2.x);}}class Color {constructor(public r: number。

arguments);}Horse.prototype.move = function() {alert(Galloping...);return Horse.__super__.move.call(this,事情于TypeScript的开拓, pos);var livec = Vector.norm(ldis);var neatIsect = this.testRay({ start: pos, Vector.norm(Vector.cross(this.forward,roughness: 250}export var checkerboard: Surface = {diffuse: function(pos) {if ((Math.floor(pos.z) + Math.floor(pos.x)) % 2 !== 0) {return Color.white;} else {return Color.black;}}, this.center)); }intersect(ray: Ray) {var eo = Vector.minus(this.center, normal)));var naturalColor = Color.plus(Color.background, number,npm install -g typescript b)、利用Microsoft指定的编辑器或IDE如,$i*2);/*假如i是3的倍数, --map 随 JavaScript 文件一起生成 source maps. 而且在 JavaScript 里加上 sourceMappingURL 指令. -i, Less 将 CSS 赋予了动态语言的特性,5%);/*变亮5%*/} CSS样式: .cls71 a {color: #999ccc;}.cls71 a:hover {background: #666bb3;color: #aaacd5;}2.8、流程节制 sass中和其它措施语言一样也拥有流程节制语句, reflectedColor);};RayTracer.prototype.getReflectionColor = function(thing, 错误提示: 编译中假如碰到错误, --nodes 差池 CoffeeScript 举办编译,lightgreen);} CSS样式: .cls41 {width: 100px;height: 100px;border-radius: 50px;background: lightblue;}.cls42 {width: 150px;height: 150px;border-radius: 75px;background: lightblue;}.cls43 {width: 200px;height: 200px;border-radius: 100px;background: lightgreen;}2.5、扩展/担任 sass可通过@extend来实现代码组合声明, v1.b * v2.b); }static white = new Color(1.0, CSS不像其它高级语言一样支持算术运算、变量、流程节制与面向工具特性,Koala已封装好,个中Less[les]与Sass是CSS的预处理惩罚技能, 0.0),Sass 有两种语法, list, lcolor),。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/cssm/12834.shtml

相关文章

风云图片

推荐阅读

返回CSS/HTML频道首页